<?php
namespace BP\En;
require_once("java/lang/reflect/Method.php");
require_once("BP/Tools/StringHelper.php");
class RefMethod {
	public $Height;	// int
	public $Width;	// int
	public $Target;	// String
	public $refMethodType;	// RefMethodType
	public $RefAttrKey;	// String
	public $RefAttrLinkLabel;	// String
	public $GroupName;	// String
	public $IsForEns;	// boolean
	protected $_HisAttrs;	// Attrs
	public $Index;	// int
	public $Visable;	// boolean
	public $IsCanBatch;	// boolean
	public $Title;	// String
	public $Warning;	// String
	public $ClassMethodName;	// String
	public $Icon;	// String
	public $ToolTip;	// String
	public $PKVal;	// Object
	public $HisEn;	// Entity
	public $PKs;	// String[]
	private function __init() { // default class members
		$this->Height = 600;
		$this->Width = 800;
		$this->Target = "_B123";
		$this->refMethodType = $BP->En->RefMethodType->Func;
		$this->RefAttrKey = NULL;
		$this->RefAttrLinkLabel = NULL;
		$this->GroupName = NULL;
		$this->IsForEns =  TRUE ;
		$this->_HisAttrs = NULL;
		$this->Index = 0;
		$this->Visable =  TRUE ;
		$this->IsCanBatch =  FALSE ;
		$this->Title = NULL;
		$this->Warning = NULL;
		$this->ClassMethodName = NULL;
		$this->Icon = NULL;
		$this->ToolTip = NULL;
		$this->PKVal = "PKVal";
		$this->HisEn = NULL;
		$this->PKs = (new String(""))->split("[.]", -1);
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	public function getHisAttrs () 
	{
		if (($this->_HisAttrs == NULL))
		{
			$this->_HisAttrs = Attrs::constructor__();
		}
		return $this->_HisAttrs;
	}
	public function setHisAttrs ($value) // [Attrs value]
	{
		$this->_HisAttrs = $value;
	}
	public function GetIcon ($path) // [String path]
	{
		if (($this->Icon == NULL))
		{
			return (("<img src='" . $path) . "WF/Img/Btn/Do.gif'  border=0 />");
		}
		else
		{
			$url = $this->Icon;
			if (!$this->Icon->contains("http://"))
			{
				$this->Icon = ($path . $this->Icon);
			}
			return (("<img src='" . $url) . "'  border=0 />");
		}
	}
	public function Do ($paras) // [Object[] paras]
	{
		$str = $StringHelper->trim($this->ClassMethodName, ' ', ';', '.');
		$pos = $str->lastIndexOf(".");
		$clas = $str->substring(0, $pos);
		$meth = $str->substring(($pos + 1), $str->length());
		if ($meth->contains("()"))
		{
			$meth = $meth->replace("()", "");
		}
		if ((NULL == $this->HisEn))
		{
			$this->HisEn = ClassFactory::GetEn($clas);
			$attrs = $this->HisEn->getEnMap()->getAttrs();
		}
		$mp = NULL;
		$mps = $this->HisEn->getClass()->getMethods();
		$length = count($mps) /*from: mps.length*/;
		for ($i = 0; ($i < $length); ++$i) 
		{
			if ($mps[$i]->getName()->equals($meth))
			{
				$mp = $mps[$i];
				break;
			}
		}
		if ((NULL == $mp))
			throw new Exception((("@对象实例中没有找到方法[" . $meth) . "]�?"));
		try 
		{
			if ((count($mp->getParameterTypes()) /*from: mp.getParameterTypes().length*/ > 0))
			{
				return $mp->invoke($this->HisEn, $paras);
			}
			else
			{
				return $mp->invoke($this->HisEn);
			}
		}
		catch (Exception $e)
		{
			$cause = $e->getCause()->getMessage();
			$msg = $e->getMessage();
			if (!(is_null($msg) || $msg == ''))
			{
				$cause = (($msg . "\n") . $cause);
			}
			$strs = "";
			if (($paras == NULL))
			{
				throw new \Exception($cause);
			}
			else
			{
				foreach ($paras as $obj) 				{
					$strs += (("para= " . $obj) . "\n<br>");
				}
				throw new Exception((($cause . "  more info:") . $strs));
			}
		}
	}
}
?>
